<?php
	require_once('config/config.php');
	
	function get_id_product($nomparfum)
	{
		global $gp_db, $candle;
		$q = "SELECT id FROM _fo_products WHERE name = '" . addslashes($nomparfum) . "'";
		if ($candle)
			$q .= ' && id_line = 7';
		$res = $gp_db -> fetchArray_one($q);
		return $res["id"];
	}
	
	if (strstr(REQUESTURI, "http://www."))
	{
		$r = str_replace('http://www.', 'http://', REQUESTURI);
		$r = str_replace('//', '/', $r);
		$r = str_replace('http:/', 'http://', $r);
		header("HTTP/1.1 301 Moved Permanently");
		header('Location: ' . $r);
	}
	
	if (strstr(REQUESTURI, '/perfumes') || strstr(REQUESTURI, '/candles'))
	{
		$page = 'product';
		$candle = false;
		define('PAGE', $page);
		if (strstr(REQUESTURI, '/perfumes'))
			list($dummy, $nomparfum) = explode('/perfumes/', REQUESTURI, 2);
		if (strstr(REQUESTURI, '/candles'))
		{
			list($dummy, $nomparfum) = explode('/candles/', REQUESTURI, 2);
			$candle = true;
		}
		$nomparfum = str_replace('-', ' ', $nomparfum);
		$nomparfum = str_replace('/', '', $nomparfum);
		if ($nomparfum == '')
			$nomparfum = 'cdg';
		$id = call_fonction_cache('get_id_product', $nomparfum, (3600 * 24 * 180));
		$GLOBALS["id"] = $id;
		if (!strlen($id))
			$page = 'index';
		GP_dispatch::getInstance();
		exit;
	}
	list($dummy, $urirw) = explode(dirname($_SERVER["SCRIPT_NAME"]) . '/', $_SERVER['REQUEST_URI'], 2);
	$tabrw = explode('/', $urirw);
	$der = $tabrw[count($tabrw) - 1];
	
	if (!strstr($der, '.html'))
	{
		$urirw .= '.html';
		$tabrw = explode('/', $urirw);
	}

	$lngrw = $tabrw[1];
	$page = $tabrw[2];
	$page = str_replace('.html', '', $page);
	
	$nb = count($tabrw);
	
	if ($nb > 3)
	{
		$i = 3;
		while ($i < $nb)
		{
			$cle = trim($tabrw[$i]);
			$val = trim($tabrw[$i + 1]);
			$val = str_replace('.html', '', $val);
			$GLOBALS[$cle] = $val;
			$i += 2;
		}
	}
	
	if (!is_file(DIR_SCRIPTS . $page . '.' . EXTENSION) || !is_file(DIR_HTML . $page . '.' . EXTENSION_TPL))
		$page = PAGE404;
	if (MAINTENANCE)
	{
		$page = 'travaux';
		$urirw = DIR_HTML_STATIQUE . '/' . APPLNG . '/' . PAGEMAINTENANCE . '.html';
	}
	
	define('PAGE', $page);
	
	if ($page == PAGE404)
		$urirw = DIR_HTML_STATIQUE . '/' . APPLNG . '/' . PAGE404 . '.html';
	GP_dispatch :: getInstance();
?>